package com.github.eclipseace.mybatis.pagination.dialect;

import com.github.eclipseace.mybatis.util.StringUtils;

/**
 * @author eclipseAce
 */
public enum PaginationDialectType {
	MYSQL(MySqlPaginationDialect.class);

	private final Class<? extends PaginationDialect> dialectClass;

	private PaginationDialectType(Class<? extends PaginationDialect> dialectClass) {
		this.dialectClass = dialectClass;
	}

	public Class<? extends PaginationDialect> getDialectClass() {
		return dialectClass;
	}

	public static PaginationDialectType fromString(String string) {
		if (StringUtils.isNotEmpty(string)) {
			for (PaginationDialectType type : values()) {
				if (type.name().equalsIgnoreCase(string)) {
					return type;
				}
				if (type.getDialectClass().getName().equals(string)) {
					return type;
				}
			}
		}
		return null;
	}
}
